package com.tshopping.dao;

import com.tshopping.bean.Goods;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

@Repository
public interface GoodsDao {

    @Insert("insert into goods(name,description,cover,price,stock,user,level,freight,store) values(#{name},#{description},#{cover},#{price},#{stock},#{user},#{level},#{freight},#{store})")
    @Options(useGeneratedKeys = true, keyColumn = "id")
    boolean insertGoodsByGoodsInformation(Goods goods);

    @Select("select * from goods where store=#{store} and user=#{user} and isApprove=1 limit #{start},#{size}")
    ArrayList<Goods> selectGoodsByStoreIDAndUserID(@Param("store") int store, @Param("user") int user, @Param("start") int start, @Param("size") int size);

    @Update("update goods set isSell=#{isSell} where id=#{id}")
    boolean updateGoodsIsSellById(@Param("isSell") int isSell, @Param("id") int id);

    @Update("update goods set name=#{name},description=#{description},cover=#{cover},price=#{price},stock=#{stock},level=#{level},freight=#{freight},isApprove=0 where id=#{id}")
    boolean updateGoodsById(Goods goods);

    @Delete("delete from goods where id=#{id}")
    boolean deleteGoodsById(@Param("id") int id);

    @Select("select * from goods")
    ArrayList<Goods> selectAllGoods();

    @Select("select * from goods where id=#{id}")
    Goods selectGoodsByGoodsId(@Param("id") int id);

    @Select("select count(*) from goods where store=#{store} and user=#{user} and isApprove=1")
    int selectCountByStoreAndUser(@Param("store") int store, @Param("user") int user);

    @Select("select count(*) from goods")
    int selectAllGoodsCount();

    @Select("select * from goods limit #{start},#{size}")
    ArrayList<Goods> getAllGoods(@Param("start")int start,@Param("size")int size);

    @Update("update goods set isApprove=#{isApprove} where id=#{id}")
    boolean updateIsApprove(@Param("isApprove")int isApprove,@Param("id")int id);

    @Select("select * from goods where isApprove=1 and isSell=1 limit #{start},#{size}")
    ArrayList<Goods> getAllApproveSellGoods();

    @Select("select count(*) from goods where isApprove=1 and isSell=1 limit #{start},#{size}")
    int getAllApproveAndSellGoods(@Param("start")int start,@Param("size")int size);

    @Select("select * from goods where isApprove=1 and isSell=1 and level=#{level} limit #{start},#{size}")
    ArrayList<Goods> getLevelGoods(@Param("level")int level,@Param("start")int start,@Param("size")int size);

}
